INPUT = """\
5
5 4 5 4 5
6 4 7 5 4 9 4 3
3 4 3 2 3 1 2 5
9 3 6 4 2 1 4 3
2 5 4 3 7 7 1 6
"""

from io import StringIO

N = None  # 层数。
node_number = []  # 每层多少结点。
edge_weights = {}  # 相邻两层结点之间的边权。
dp = {}  # 保存某结点到终点的最短路径，还有方向（向上u，向下d）。


def ReadInput(stream: StringIO):
    global N, node_number, edge_weights
    N = int(stream.readline())
    node_number = list(map(int, stream.readline().split()))
    assert len(node_number) == N
    for i in range(N - 1):
        line = stream.readline()
        for j, s in enumerate(line.split()):
            edge_weights[(i, j)] = int(s)


def BP():
    global dp
    end = N - 1
    start = 0
    # 初始化：终点到终点的距离为0。
    for i in range(node_number[start]):
        dp[(i, i)] = (0, None)

    for i in range(1, N):
        # 逐层求解
        for j in range(node_number[i]):
            # 枚举每层的各个节点
            min_val=999
            # 若有向上的路径
            if 
            # 若有向下的路径


def main():
    data = StringIO(INPUT)
    ReadInput(data)
    print(N)
    print(node_number)
    print(edge_weights)
    print(INPUT)


main()
